class Thread3 implements Runnable {
    static int a = 1;
    static int b = 65;
    static Boolean flag = true;
    private String name;
    Object obj = new Object();

    public Thread3(String name, Object obj) {
        this.name = name;
        this.obj = obj;
    }

    @Override
    public void run() {
        while (true) {
            synchronized (obj) {
                if (a > 50 && b > 89) {
                    obj.notifyAll();
                    if(!flag){
                        System.out.println(name + "在打印：" + (char)b++);
                    }
                    break;
                }
                while(flag){
                    try {
                        flag = false;
                        System.out.println(name + "在打印：" + a++);
                        System.out.println(name + "在打印：" + a++);
                        obj.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println(name + "在打印：" + (char)b++);
                flag = true;
                obj.notifyAll();
            }
        }
    }
}

public class T3 {
    public static void main(String[] args) {
        Object obj = new Object();
        Thread t1 = new Thread(new Thread3("线程一",obj));
        Thread t2 = new Thread(new Thread3("线程二",obj));
        t1.start();
        t2.start();
    }
}